
/**
 * 数据流转url
 * @param blobData 接口返回的数据流
 * @param types 需要转换成什么类型 例如 application/vnd.ms-excel
 * @returns url的字符串
 */
export const changeData = (blobData: any, types: string): string => {
  const blob = new Blob([blobData], { type: types })
  const url = URL.createObjectURL(blob)
  return url
}
/**
 * 下载
 * @param blobData 接口返回的数据流或者文件服务器地址
 * @param types 需要转换成什么类型 例如 application/vnd.ms-excel
 * @param name 下载的文件名称
 */
export const downData = (blobData: string, name: string = Date.parse(Date()).toString(), types?: string, ):void => {
  const blob = new Blob([blobData], { type: types })
  const link = document.createElement('a')
  link.style.display = 'none'
  if(blobData.includes('http')) {
    window.open(blobData)
    return 
  }
  if (window.navigator && window.navigator.msSaveOrOpenBlob) { // 处理ie下的兼容
    window.navigator.msSaveOrOpenBlob(blob, name);
  } else {
    const url = URL.createObjectURL(blob)
    link.href = url
    link.target = '_blank'
    link.download = name // 下载的文件名
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
  }
}